<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>注册</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript" src="../../js/jquery-3.3.1.js"></script>
	<script type="text/javascript" src="../../js/bootstrap.min.js"></script>
	<link href="../../css/bootstrap.min.css" rel="stylesheet">
  </head>
  
  <body>
  <script type="text/javascript">
  	$(document).ready(function(){
  		$.ajax({url:"${pageContext.request.contextPath}/college/findAll",
  			dataType:"json",
  			type:"post",
  			success:function(data, status){
  				for(var i = 0; i < data.data.length; i++)
  				{
  					$("#tc").append("<option value="+data.data[i].eid+">"+data.data[i].ename+"</option>");
  				}
  			}});
  	});
  	
  	function ajaxMajorFindAll(value){
  		$.ajax({
  		url:"${pageContext.request.contextPath}/major/findAll",
  		dataType:"json",
  		type:"post",
  		data:{eid:value},
  		success:function(data, status){
  			$("#tm").empty();
  			$("#tm").append("<option selected='selected'>&emsp;&emsp;</option>");
  			for(var i = 0; i < data.data.length; i++)
  			{
  				$("#tm").append("<option value="+data.data[i].mid+">"+data.data[i].mname+"</option>");
  			}	
  		}});
  	}
  	
  	function addStudent(){
  			$.ajax({
  			url:"${pageContext.request.contextPath}/student/regist",
  			dataType:"json",
  			type:"post",
  			data:{susername:$("#tu").val(), spassword:$("#tp").val(), sname:$("#tn").val(), mid:$("#tm").val()},
  			success:function(data, status){
  			if(data.code == 0)
  			{
  				$("#um").empty();
  				$("#pm").empty();
  				$("#nm").empty();
  				$("#mm").empty();
  				$("#um").html(data.data.susername);
  				$("#pm").html(data.data.spassword);
  				$("#nm").html(data.data.sname);
  				$("#mm").html(data.data.major);
  			}else if (data.code == 1){
 				alert("注册成功");
 				window.parent.top.location.href='../../top.jsp';
  			}else {
  				$("p").empty();
  				$("p").html(data.message);
  			}
  		}});
  	}
  </script>
  <h5>注册学生信息</h5>
<p style="color: red; font-weight: 100" id="p" ></p>
<form id="f">
	用户名:<input type="text" id="tu" size="16"/>
	<br/><span style="color: red; font-weight: 300" id="um"></span><br/>
	密&emsp;码:<input type="password" id="tp" size="16"/>
	<br/><span style="color: red; font-weight: 300" id="pm"></span><br/>
	姓&emsp;名:<input type="text" id="tn" size="16" />
	<br/><span style="color: red; font-weight: 300" id="nm"></span><br/>
	学&emsp;院:<select id = "tc" onchange="ajaxMajorFindAll(this.value)">
			 		<option selected="selected"></option>
			  </select>
		<br/>
		<span style="color: red; font-weight: 300" id="mm"></span>
		<br/>
	专&emsp;业:<select id = "tm" onchange="ajaxTeacherFindByMid(this.value)">
		    </select>
		<br/>
		<br/>
	<input type="button" value="提交信息" onclick="addStudent()"/>
</form>
  </body>
</html>
